package com.wholesale.utils;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.PixelFormat;
import android.graphics.drawable.Drawable;

import com.wholesale.beans.GoodsCategory;
import com.wholesale.beans.LoginResponse;
import com.wholesale.beans.UserInfo;
import com.wholesale.beans.WhoAttribute;

public class Constants {
	// web service URl
	public final static String WEB_SERVICE_URL = "http://eastapp.gicp.net:8080/ServiceApp/WholesaleWS";
	public final static String WEB_SEVICE_NAMESPACE = "http://webservice.wholesale.com/";

	public static String IMAGE_URL = "http://img.wholesale-dress.net";

	public static String paypalReceiver = "billing@wholesale-dress.net";

	public static String paypalAppId = "APP-4SK60521RY505002G";

	public static Context appContext;

	// 保存用户登录信息
	public static UserInfo userInfo = null;

	public static LoginResponse loginResponse = null;

	private static int curNavigationId = 0;

	public static int moreSelectedIndex = -1;

	public static int myAcountSelectedIndex = -1;

	public static int categoryLevel = 1;

	public static GoodsCategory catInfoLeve2;

	public static GoodsCategory catInfoLeve1;

	public static String GOODSDETAIL_COMEFROM_ID = "goodsDetailComefromId";
	public static String GOODSDETAIL_LEFTBTN_NAME = "goodsDetailLeftBtnName";
	public static String GOODSDETAIL_HEAD_NAME = "goodsDetailHeadName";
	public static String GOODSLIST_COMEFROM_ID = "goodsListComefromId";
	public static String GOODSLIST_LEFTBTN_NAME = "goodsListLeftBtnName";
	public static String GOODSLIST_HEAD_NAME = "goodsListHeadName";

	public static ArrayList<WhoAttribute> whoAttributeList;

	public static HashMap<String, String> sysPrarms = new HashMap<String, String>();

	public static int menFormalId = 220;

	public static String getWhoAttributeName(int attrId) {
		String name = null;
		if (whoAttributeList != null) {
			for (WhoAttribute whoAttribute : whoAttributeList) {
				if (whoAttribute.getAttrId() == attrId) {
					name = whoAttribute.getAttrName();
					break;
				}
			}
		}
		return name;
	}

	public static int SEARCH_ID = -1;

	public static int getCurNavigationId() {
		return curNavigationId;
	}

	public static void setCurNavigationId(int navigationId) {
		Constants.curNavigationId = navigationId;
	}

	public static double getTwoDecimal(double d) {
		BigDecimal bd = new BigDecimal(Double.toString(d));
		double result = bd.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
		return result;
	}

	public static double getTwoDecimalFloor(double d) {
		BigDecimal bd = new BigDecimal(Double.toString(d));
		double result = bd.setScale(2, BigDecimal.ROUND_FLOOR).doubleValue();
		return result;
	}

	public static Bitmap drawableToBitmap(Drawable drawable) {
		Bitmap bitmap = null;
		if (null != drawable) {
			bitmap = Bitmap
					.createBitmap(
							drawable.getIntrinsicWidth(),
							drawable.getIntrinsicHeight(),
							drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
									: Bitmap.Config.RGB_565);
			Canvas canvas = new Canvas(bitmap);
			// canvas.setBitmap(bitmap);
			drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),
					drawable.getIntrinsicHeight());
			drawable.draw(canvas);
		}

		return bitmap;
	}

	public static boolean isStringEmpty(String str) {
		return str == null || str.equals("");
	}

	public static boolean isStringNotEmpty(String str) {
		return !isStringEmpty(str);
	}

	public static boolean toMyAccount = false;
	public static double use_balance = 0;

	public static boolean initMoreActivity = false;

	public final static int CMD_STOP_SERVICE = -1;
	public final static int CMD_OPENCAR_SERVICE = 0;
	public final static int CMD_ADDCAR_SERVICE = 1;
	public final static int CMD_DELETECAR_SERVICE = 2;
	public final static int CMD_UPDATECAR_SERVICE = 3;
	public final static int CMD_LOGIN_SERVICE = 4;
	public final static int CMD_LOGOUT_SERVICE = 5;
	public final static int CMD_MYACCOUNT_SERVICE = 6;
	public final static int CMD_ADDFAVORITE_SERVICE = 7;
}
